<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <p:fieldset legend="Lista de reservas de ambiente">
            <h:form id="formReserva">
                <p:dataTable var="object" value="#{reservaAmbienteMB.reservaAmbienteList}" rowKey="#{object.codigo}">
                    <p:column headerText="Ambiente">
                        <h:outputText value="#{object.codigoAmbiente.descricao}" />  
                    </p:column>
                    <p:column headerText="Morador">
                        <h:outputText value="#{object.codigoMorador.nome}" />
                    </p:column>
                    <p:column headerText="Data Início">
                        <h:outputText value="#{object.dataInicio}" >
                            <f:convertDateTime locale="pt,BR" dateStyle="long" pattern="dd/MM/yyyy HH:mm" /> 
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Data Fim">
                        <h:outputText value="#{object.dataFim}" >
                            <f:convertDateTime locale="pt,BR" dateStyle="long" pattern="dd/MM/yyyy HH:mm" /> 
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Entregar Limpo?">
                        <h:outputText value="#{morador.estado == 0 ? 'não' : 'sim'}" />
                    </p:column>
                    <p:column selectionMode="multiple">
                        <f:facet name="header"> 
                            Vadidado?
                        </f:facet>                        
                    </p:column>
                    <p:column headerText="Editar">
                        <p:commandButton value="Editar" onclick="modalAmbiente.show()"/>
                    </p:column>
                    <p:column headerText="Excluir">
                        <p:commandButton value="Excluir" onclick="modalExclusao.show()"/>
                    </p:column>
                </p:dataTable>
                <p:commandButton value="Add" onclick="modalAmbiente.show()"/>
            </h:form> 
        </p:fieldset>  

        <p:dialog header="Cadastro reserva de ambiente" widgetVar="modalAmbiente" modal="true">
            <h:form id="cadastroAmbiente"> 
                <p:messages/>
                <h:panelGrid columns="2">
                    <h:outputLabel value="Ambiente"/>
                    <h:inputHidden/>                    
                    <p:selectOneMenu value="#{reservaAmbienteMB.reservaAmbiente.codigoAmbiente}" effect="fade" rendered="true" requiredMessage="Selecione um ambiente que deseja fazer a reserva.">  
                        <f:selectItem itemLabel="Selecione..."/> 
                        <f:selectItems value="#{reservaAmbienteMB.ambienteList}" var="object" itemLabel="#{object.descricao}" itemValue="#{object}"/>  
                    </p:selectOneMenu> 
                    <h:inputHidden/>
                    
                    <h:outputLabel value="Data Início"/>
                    <h:outputLabel value="Data Fim"/>
                    
                    <p:calendar value="#{reservaAmbienteMB.reservaAmbiente.dataInicio}" rendered="true" requiredMessage="Preencha uma data de inicio."/>                    
                    <p:calendar value="#{reservaAmbienteMB.reservaAmbiente.dataFim}" rendered="true" requiredMessage="Preencha uma data de fim."/>  
                    
                    <h:outputLabel value="Entrega Limpo?"/>
                    <h:inputHidden/>
                    <h:selectOneRadio value="#{reservaAmbienteMB.reservaAmbiente.entregaLimpo}">
                        <f:selectItem itemValue="1" itemLabel="Sim" />
                        <f:selectItem itemValue="0" itemLabel="Não" />
                    </h:selectOneRadio>
                    <h:inputHidden/>
                    
                    <p:commandButton value="Cancelar" process="@this" actionListener="#{reservaAmbienteMB.clean()}" oncomplete="modalAmbiente.hide()"/>                    
                    <p:commandButton id="btnSalvar" value="Salvar" update="cadastroAmbiente" action="#{reservaAmbienteMB.save()}" oncomplete="modalTermo.show()"/>
                    
                </h:panelGrid>
            </h:form>

        </p:dialog>
        
        <p:dialog header="Aviso" widgetVar="modalTermo" modal="true">
            <h:form id="sucesso">       
                <h:panelGrid columns="2">
                    <h:outputLabel value="Reserva efetuada com Sucesso!"/>
                    <h:inputHidden/>        
                    
                    <p:commandButton value="Fechar" process="@this" action="#{reservaAmbienteMB.save()}" oncomplete="modalTermo.hide() modalAmbiente.hide()"/>
                    
                </h:panelGrid>
            </h:form>

        </p:dialog>
        
        <p:dialog header="Aviso" widgetVar="modalExclusao" modal="true">
            <h:form id="exclusao">       
                <h:panelGrid columns="2">
                    <h:outputLabel value="Reserva excluída com Sucesso!"/>
                    <h:inputHidden/>        
                    
                    <p:commandButton value="Fechar" process="@this" oncomplete="modalExclusao.hide()"/>
                    
                </h:panelGrid>
            </h:form>

        </p:dialog>
               
    </h:body>
</html>

